﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using InTheHand.Storage;
using Windows.ApplicationModel.Store;
using InTheHand.ApplicationModel.Store;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace StoreApp
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();

            SYSTEM_INFO si;

            GetNativeSystemInfo(out si);
            System.Diagnostics.Debug.WriteLine(si.dwNumberOfProcessors);
        }

        [System.Runtime.InteropServices.DllImport("kernel32")]
        private static extern void GetNativeSystemInfo(out SYSTEM_INFO lpSystemInfo);

        [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
        private struct SYSTEM_INFO
        {
            [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.U2)]
            public ProcessorArchitecture wProcessorArchitecture;
            ushort wReserved;

            public uint dwPageSize;
            public IntPtr lpMinimumApplicationAddress;
            public IntPtr lpMaximumApplicationAddress;
            public uint dwActiveProcessorMask;
            public uint dwNumberOfProcessors;
            uint dwProcessorType;
            public uint dwAllocationGranularity;
            public ushort wProcessorLevel;
            public ushort wProcessorRevision;
        }

        private enum ProcessorArchitecture : ushort
        {
            AMD64 = 9,
            ARM = 12,
            IA64 = 6,
            INTEL = 0,
            UNKNOWN = 0xffff,
        }

        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            InTheHand.ApplicationModel.Calls.PhoneCallManager.ShowPhoneCallUI("+447968449031", "International Rescue");

            foreach(Windows.Devices.Enumeration.Pnp.PnpObject obj in await Windows.Devices.Enumeration.Pnp.PnpObject.FindAllAsync(Windows.Devices.Enumeration.Pnp.PnpObjectType.Device, new List<string>() { "System.Devices.DeviceInstanceId" }))
            {
                System.Diagnostics.Debug.WriteLine(obj.Id);
            }

            //bool be = await InTheHand.ApplicationModel.Store.CurrentApp.RequestReviewAsync();

            /*Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation di = new Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation();
            string s = di.OperatingSystem;
            InTheHand.Phone.Tasks.SmsComposeTask sct = new InTheHand.Phone.Tasks.SmsComposeTask();
            sct.To = "07968449031";
            //sct.Body = "Hello world!";
            sct.Show();*/

            /*InTheHand.Phone.Tasks.EmailComposeTask ect = new InTheHand.Phone.Tasks.EmailComposeTask();
            ect.To = "peter@peterfoot.net";
            ect.Subject = "My Crazy=Subject";
            ect.Body = "This is average text\r\nover several!lines";
            ect.Show();*/
            /*System.Diagnostics.Debug.WriteLine(System.Environment.TickCount);
            Windows.Storage.IStorageItem item = await Windows.Storage.ApplicationData.Current.LocalFolder.TryGetItemAsync("cheese");
            System.Diagnostics.Debug.WriteLine(System.Environment.TickCount);
            if (item == null)
            {
                Windows.Storage.IStorageItem i = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync("cheese");
                item = await Windows.Storage.ApplicationData.Current.LocalFolder.TryGetItemAsync("cheese");
                System.Diagnostics.Debug.WriteLine(System.Environment.TickCount);
            }

            Windows.Storage.IStorageItem item3 = await ((Windows.Storage.StorageFolder)item).CreateFolderAsync("subcheese");
            Windows.Storage.StorageFile file = await ((Windows.Storage.StorageFolder)item3).CreateFileAsync("cheesefile.txt");
            await ((Windows.Storage.StorageFolder)item).DeleteAsync();*/


            /*Windows.ApplicationModel.Store.
            InTheHand.Phone.Tasks.MarketplaceSearchTask mst = new InTheHand.Phone.Tasks.MarketplaceSearchTask();
            mst.SearchTerms = "In The Hand";
            mst.Show();*/
        }
    }
}
